package com.ozonetel;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author <a href="mailto:sudhakargupta.s@gmail.com">SudhakarGupta</a>
 */
public class StdConstants {

    private Properties STD_CONSTANTS;
    private static volatile StdConstants INSTANCE;
    /** mobile types */
    public static final String FIXED = "FIXED";
    public static final String MOBILE = "MOBILE";
    
    /**
     * Transient log to prevent session synchronization issues - children can use instance for logging.
     */
    protected transient static final Log log = LogFactory.getLog(StdConstants.class);

    protected StdConstants() {
        STD_CONSTANTS = new Properties();
        try {
            STD_CONSTANTS.load(this.getClass().getClassLoader().getResourceAsStream("std_series.properties"));
//            STD_CONSTANTS.load(new FileInputStream(new File("./std_series.properties")));
            log.debug("STD constants are loaded successfully..");
        } catch (FileNotFoundException e) {
            log.error(e.getMessage(), e);
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

    public static StdConstants getInstance() {
        if (INSTANCE == null) {
            synchronized (StdConstants.class) {
                if (INSTANCE == null) {
                    INSTANCE = new StdConstants();
                }
            }
        }
        return INSTANCE;
    }

    public static String getConstant(String name) {
        return StdConstants.getInstance().STD_CONSTANTS.getProperty(name);
    }
}